import java.util.Objects;

class Person{
    public String name = "zhangsan";
    public int age = 10;
    public Person(String name, int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) //判断两者的是否是同一个引用，即地址是否相等
            return true;
        if (o == null)//判断o是不是空
            return false;
        if (!(o instanceof Person))//判断类型是否相等
            return false ;
        Person person = (Person) o;//向下转型，因为父类无法调用子类的成员
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }/**/

    @Override
    public String toString() {
        return "Person{" + "name=" + name + ", age=" + age + '}';
    }
}
public class Test1 {
    public static void main(String[] args) {
        Person person = new Person("zhangsan",10);
        Person person1 = new Person("zhangsan",10);
        System.out.println(person.hashCode());
        System.out.println(person1.hashCode());
        //System.out.println(person.equals(person1));
    }
}
